package dungnt.vpoint.mathtest.db;

import java.util.List;

import dungnt.vpoint.mathtest.R;
import dungnt.vpoint.mathtest.highscore.HighScoreMain;

import android.content.Context;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ScoreAdapter extends BaseAdapter{
	private Context context;
	private List<User> list;
	static int id;
	public ScoreAdapter(Context context, List<User> i) {
		this.context= context;
		list=i;
		id = 0;
	}
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		View view;
		if(convertView==null){
			Typeface userFont = Typeface.createFromAsset(HighScoreMain.context.getAssets(), "arial_regular.ttf");
			LayoutInflater layoutInflater = LayoutInflater.from(context);
			view = layoutInflater.inflate(R.layout.highscore_listview, null);
			
			TextView lblId = (TextView)view.findViewById(R.id.alert3_id);
			id++;
			lblId.setText(String.valueOf(id));
			lblId.setTypeface(userFont);
			
			TextView lblName = (TextView)view.findViewById(R.id.alert3_name);
			lblName.setText(list.get(position).getName().toString());
			lblName.setTypeface(userFont);
			
			TextView lblScore = (TextView)view.findViewById(R.id.alert3_score);
			lblScore.setText(String.valueOf(list.get(position).getScore()));
			lblScore.setTypeface(userFont);
			
			TextView lblTime = (TextView)view.findViewById(R.id.alert3_time);
			lblTime.setText(list.get(position).getTime().toString());
			lblTime.setTypeface(userFont);
			
		}else{
			view =convertView;
		}
		
		return view;
	}

}
